Skip to content

Emit missing-fields diagnostics from inference#22336

Open
Twil3akine wants to merge 6 commits into
rust-lang:masterfrom
Twil3akine:missing-fields-inference
Open

Emit missing-fields diagnostics from inference#22336
Twil3akine wants to merge 6 commits into
rust-lang:masterfrom
Twil3akine:missing-fields-inference

Conversation

@Twil3akine

@Twil3akine Twil3akine commented May 10, 2026

Copy link
Copy Markdown

Implements one diagnostic FIXME from #22140.

This changes record-literal missing-fields diagnostics to be emitted from inference, while reusing the existing MissingFields diagnostic.

MissingFields already represents record literal/pattern missing field diagnostics and is rendered as rustc hard error E0063, so adding a separate diagnostic would duplicate behavior.

This PR:

  • reuses the existing MissingFields diagnostic
  • moves record-literal missing-fields emission from body validation into inference
  • keeps the existing record-pattern body validation path intact
  • does not add a new ide-assist or quick fix

Validated with:

cargo +nightly-2026-04-30 test -p ide-diagnostics missing_fields
cargo +nightly-2026-04-30 test -p ide-diagnostics
cargo +nightly-2026-04-30 test -p hir-ty
cargo +nightly-2026-04-30 test -p hir

AI assistance disclosure:
I used ChatGPT to help review the implementation plan and draft this PR description. I reviewed the generated suggestions before submitting.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 10, 2026
Comment thread crates/hir-ty/src/infer/expr.rs Outdated
Comment thread crates/hir-ty/src/infer/expr.rs Outdated
remaining_fields.contains_key(&field.name).then_some(field_idx)
})
.collect::<Vec<_>>();
if !missing_fields.is_empty() {

@ChayimFriedman2 ChayimFriedman2 May 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if is redundant, we already checked that above.

View changes since the review

Comment thread crates/hir/src/diagnostics.rs
Comment thread crates/hir/src/lib.rs Outdated
expr_store_diagnostics(db, acc, source_map);

let infer = InferenceResult::of(db, id);
let mut delayed_missing_fields_diagnostics = Vec::new();

@ChayimFriedman2 ChayimFriedman2 May 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you delay this? I see no reason for that.

View changes since the review

@rustbot

This comment has been minimized.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

@Twil3akine, what's the status of this?

Twil3akine and others added 5 commits May 26, 2026 09:18
Co-authored-by: Chayim Refael Friedman <chayimfr@gmail.com>
Use the current type-owner variable when emitting delayed missing-fields diagnostics after the upstream diagnostics plumbing rename.

AI assistance disclosure: ChatGPT helped identify and validate this minimal compile fix. I reviewed the change before committing.
@Twil3akine Twil3akine force-pushed the missing-fields-inference branch from 2042451 to f0e1250 Compare May 26, 2026 00:25
@rustbot

rustbot commented May 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Twil3akine

Twil3akine commented May 26, 2026

Copy link
Copy Markdown
Author

@ChayimFriedman2

Thanks for the follow-up.

I've rebased the PR and resolved the conflicts.

Regarding the diagnostic ordering change mentioned above: should I proceed with updating the tests so they don't depend on the diagnostic order? I'd appreciate your thoughts.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Diagnostics order should not affect anything. If there are tests that depend on it, that's weird and maybe a bug. Feel free to update them. Definitely don't complicate the code to change ordering, anyway.

@Twil3akine

Copy link
Copy Markdown
Author

Sorry for the late reply.

This may be due to my implementation, but removing the delay causes some tests to fail. Would it be okay to proceed by removing the delay and updating the tests accordingly?

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Remove it, update the tests, and I'll see if there is a bug in them.

Remove the delayed emission of missing-fields inference diagnostics and make diagnostic fix tests select the matching assist result instead of depending on diagnostic ordering.

AI assistance disclosure: I used ChatGPT to help implement and verify this follow-up change.
@Twil3akine

Twil3akine commented May 28, 2026

Copy link
Copy Markdown
Author

I done, pushed the update.

I removed the delayed emission and updated the diagnostic fix test helper so it selects the matching fix result instead of relying on diagnostic ordering.

Could you take another look when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants